package com.yfp.machine.service.impl;

import com.yfp.machine.domain.MachinePing;
import com.yfp.machine.mapper.MachinePingMapper;
import com.yfp.machine.service.MachinePingService;
import jakarta.annotation.Resource;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;


/**
 * (MachinePing)表服务实现类
 *
 *
 * @since 2023-12-14 14:24:50
 */
@Service("machinePingService")
public class MachinePingServiceImpl implements MachinePingService {
    @Resource
    private MachinePingMapper machinePingMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param machineId 主键
     * @return 实例对象
     */
    @Override
    public MachinePing queryById(String machineId) {
        return this.machinePingMapper.queryById(machineId);
    }

    /**
     * 分页查询
     *
     * @param machinePing 筛选条件
     * @param pageRequest 分页对象
     * @return 查询结果
     */
    @Override
    public Page<MachinePing> queryByPage(MachinePing machinePing, PageRequest pageRequest) {
        long total = this.machinePingMapper.count(machinePing);
        return new PageImpl<>(this.machinePingMapper.queryAllByLimit(machinePing, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param machinePing 实例对象
     * @return 实例对象
     */
    @Override
    public MachinePing insert(MachinePing machinePing) {
        this.machinePingMapper.insert(machinePing);
        return machinePing;
    }

    /**
     * 修改数据
     *
     * @param machinePing 实例对象
     * @return 实例对象
     */
    @Override
    public MachinePing update(MachinePing machinePing) {
        this.machinePingMapper.update(machinePing);
        return this.queryById(machinePing.getMachineId());
    }

    /**
     * 通过主键删除数据
     *
     * @param machineId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String machineId) {
        return this.machinePingMapper.deleteById(machineId) > 0;
    }
}
